package com.unsiv.helicopter.entity;

import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import com.unsiv.helicopter.entity.Accelerator.OnThrottleChangeListener;
/**
 * <p>油门仪表盘</p>
 * @author fanzhen
 * @time   5:52:27 PM Oct 30, 2011
 * @email  fanzhen.meng@gmail.com
 * @qq     474146502
 */
public class Dashboard extends Sprite implements OnThrottleChangeListener{
//	private float radius_x = 150;
//	private float radius_y = 150;
//	Line line;
	Sprite pointer;
	public Dashboard(float pX, float pY,float pWidth, float pHeight,TextureRegion pTextureRegion,TextureRegion pPointerRegion,Accelerator accelerator) {
		super(pX, pY,pWidth,pHeight,pTextureRegion);
		accelerator.setOnThrottleChangeListener(this);
		this.pointer = new Sprite(0,this.getHeightScaled()-40, pPointerRegion);
		this.pointer.setRotationCenter(pointer.getScaleX()+pointer.getWidthScaled()-60, pointer.getScaleY()+60);
		this.attachChild(pointer);
//		line = new Line(this.radius_x-100,this.radius_y,0,this.radius_y);
//		line.setColor(1f, 0f, 0f);
//		line.setLineWidth(15f);
//		line.setRotationCenter(line.getScaleX()+100, line.getScaleY());
//		this.attachChild(line);
	}
	@Override
	public void onThrottleChange(int throttle) {
		float angel = (throttle * 90) / 255;
		if(angel>90)angel = 90f;
		if(angel<0)angel = 0f;
//		line.setRotation(90f-angel);
		this.pointer.setRotation(90f-angel);
	}
}